package com.test.uiapp2.function.Contacts;

import android.util.Log;

import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;

import com.test.uiapp2.base.TestBase;
import com.test.uiapp2.element.Base.BaseElement;
import com.test.uiapp2.element.Contacts.ContactsElement;

import java.io.IOException;

public class ContactsFunction  extends TestBase {
    //添加联系人
    public void addContact(){
        startApp(ContactsElement.CONTACTSNAME);
        sleep(WAITTIME);
        UiObject add = getId(BaseElement.CONTACTS,ContactsElement.ADD);
        if(add.exists()){
            clickById(BaseElement.CONTACTS,ContactsElement.ADD);
            add();
        }else{
            verify("未进入通话界面",add.exists());
        }
    }
    // H5界面，暂未处理
    public void add(){
        try {
            UiObject expansion_view = getId(BaseElement.CONTACTS, ContactsElement.EXPANSION_VIEW);
            if(expansion_view.exists()){
                expansion_view.click();
                if(getTest(ContactsElement.E_MAIL).exists()){
                    boolean exists = getTest(ContactsElement.LAST_NAME).exists();
                    Log.i(TAG, "add: ="+exists);
                }else{
                    verify("键盘未收起",!getId(ContactsElement.E_MAIL).exists());
                }

            }
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }
}
